package main

import (
	"flag"
	"gitee.com/lipore/go-nio/pkg/bootstrap"
	"gitee.com/lipore/go-nio/pkg/transport/tcp"
	"gitee.com/lipore/go-nio/pkg/transport/ws"
	"gitee.com/lipore/plume/IdGenerator"
	"gitee.com/lipore/plume/logger"
	"net/http"
	_ "net/http/pprof"
	"sync"
)

func main() {
	flag.Parse()
	go func() {
		logger.Debugf("%v", http.ListenAndServe(":8080", nil))
	}()
	cgs := CreateChannelGroups()
	b := bootstrap.New(
		bootstrap.WithTsFactories(ws.NewWsFactory(IdGenerator.IdGenerator.Next), tcp.NewTcpFactory(IdGenerator.IdGenerator.Next)),
		bootstrap.WithCgs(cgs...))
	w, err := b.Listen("ws://127.0.0.1:6001")
	if err != nil {
		panic(err)
	}
	t, err := b.Listen("tcp://127.0.0.1:6000")
	if err != nil {
		panic(err)
	}
	wg := sync.WaitGroup{}
	wg.Add(1)
	go func() {
		logger.Debugf("%v", t.Serve())
		wg.Done()
	}()
	wg.Add(1)
	go func() {
		logger.Debugf("%v", w.Serve())
		wg.Done()
	}()
	wg.Wait()

	defer b.Shutdown()
}
